package com.fankui.crowd.constant;

import java.util.HashSet;
import java.util.Set;

/**
 * ClassName AccessPassResources
 * Description TODO
 * Date 2023/8/13 15:51
 *
 * @Author 范奎
 * @Since JDK 11
 */
public class AccessPassResources {
    public static final Set<String> PASS_RES_SET = new HashSet<>();
    public static final Set<String> STATIC_RES_SET = new HashSet<>();

    static {
        PASS_RES_SET.add("/");
        PASS_RES_SET.add("/auth/member/to/reg/page.html");
        PASS_RES_SET.add("/auth/member/to/login/page.html");
        PASS_RES_SET.add("/auth/member/logout.json");
        PASS_RES_SET.add("/auth/member/to/login/page.json");
        PASS_RES_SET.add("/auth/do/member/register.json");
        PASS_RES_SET.add("/auth/member/send/short/message.json");
    }

    static {
        STATIC_RES_SET.add("bootstrap");
        STATIC_RES_SET.add("css");
        STATIC_RES_SET.add("fonts");
        STATIC_RES_SET.add("img");
        STATIC_RES_SET.add("jquery");
        STATIC_RES_SET.add("layer");
        STATIC_RES_SET.add("script");
        STATIC_RES_SET.add("ztree");
    }

    public static boolean judgeCurrentServletPathWetherStaticResource(String servlePath) {
        // 1 排除字符串无效的情况
        if (servlePath == null || servlePath.length() == 0) {
            throw new RuntimeException(CrowdConstant.MESSAGE_STRING_INVALIDATE);
        }
        // 2 根据“/”拆分ServletPath字符串
        String[] split = servlePath.split("/");
        // 3 考虑到第一个斜杠左边经过拆分后得到一个空字符串是数组的第一个元素，所以需要使用下标1取第二个元素
        String firstLevelPath = split[1];
        // 4 判断是否在集合中
        return STATIC_RES_SET.contains(firstLevelPath);
    }
}
